TOOL.Category   = "Carbon Systems"
TOOL.Name     = "#Generators"
TOOL.Command    = nil
TOOL.ConfigName   = ""
if (CLIENT and GetConVarNumber("CAF_UseTab") == 1) then TOOL.Tab = "Custom Addon Framework" end

TOOL.ClientConVar["type"] = "sol_extractor"
TOOL.ClientConVar["model"] = "models/processor_carbon.mdl"

cleanup.Register('carbonsystem')

if ( CLIENT ) then
	language.Add( "Tool_sol_generator_name", "Carbon Devices" )
	language.Add( "Tool_sol_generator_desc", "Spawns A Device for use withCarbon Systems." )
	language.Add( "Tool_sol_generator_0", "Left Click: Spawn A Device. Right Click: Repair A Device" )

	language.Add( "Undone_sol_generator", "Carbon Device Undone" )
	language.Add( "Cleanup_sol_generator", "Carbon Device" )
	language.Add( "Cleaned_sol_generator", "Cleaned up all Carbon Devices" )
	language.Add( "SBoxLimit_sol_generator", "Maximum Gas Devices Reached" )
end

if not CAF or not CAF.GetAddon("Resource Distribution") then Error("Please Install Resource Distribution Addon.'" ) return end
if not CAF or not CAF.GetAddon("Life Support") then return end

if( SERVER ) then
	CreateConVar("sbox_maxsol_generator", 24)

	function Makesol_generator( ply, ang, pos, gentype, model, frozen )
		if ( !ply:CheckLimit( "sol_generator" ) ) then return nil end

		--Create generator
		local ent = ents.Create( gentype )

		-- Set
		ent:SetPos( pos )
		ent:SetAngles( ang )

		ent:Spawn()
		ent:Activate()

		ent:SetVar("Owner", ply)
		ent:SetPlayer(ply)

		ent.Class = gentype

		if (frozen) then
			local phys = ent:GetPhysicsObject()
			if (phys:IsValid()) then
				phys:EnableMotion( false )
				ply:AddFrozenPhysicsObject( ent, phys )
			end
		end

		ply:AddCount("sol_generator", ent)

		return ent
	end

	duplicator.RegisterEntityClass("Carbon Extractor", Makesol_generator, "Ang", "Pos", "Class", "model", "frozen")
	duplicator.RegisterEntityClass("Carbon Processor", Makesol_generator, "Ang", "Pos", "Class", "model", "frozen")

end
if (GAMEMODE.Name == "SpaceBuild" || SpaceBuild) then MsgAll("You need the new Spacebuild (3) to use carbon systems, you are using Spacebuild1!\n") end
if (GAMEMODE.Name == "SpaceBuild2" || SpaceBuild2) then MsgAll("You need the new Spacebuild(3) to use carbon systems, you are using Spacebuild2!\n") end
local sol_gen_models = {
	{'Carbon Extractor', 'models/processor_carbon.mdl', 'sol_extractor'},
	{"Carbon Processor", "models/processor_carbon.mdl", "sol_processor"},

}
CAF_ToolRegister( TOOL, sol_gen_models, Makesol_generator,"sol_generator",24)
